package com.dengqi.mymodule.activity.jsoup;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.dengqi.mymodule.R;
import com.dengqi.mymodule.activity.network.util.ConstantUtil;
import com.module.my.RxNet;
import com.module.retrofit.RetrofitHelper;
import com.module.retrofit.utils.HeaderUtils;
import com.module.retrofit.utils.ToastUtil;
import com.trello.rxlifecycle2.components.support.RxAppCompatActivity;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.LinkedHashMap;
import java.util.Map;


public class JSoupActivity extends RxAppCompatActivity  {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jsoup);

        //放application里面
        Map<String, String> headers = new LinkedHashMap<>();
        headers.put(ConstantUtil.HEADER_CHANNEL, "3");
        headers.put(ConstantUtil.HEADER_DEVICE, "2");
        headers.put(ConstantUtil.HEADER_VERSION, "1.0");
        headers.put(ConstantUtil.HEADER_CID, "0");
        headers.put(ConstantUtil.HEADER_LAT, "0");
        headers.put(ConstantUtil.HEADER_LNG, "0");
        HeaderUtils.saveHeaders(headers);

        JSPresenter presenter = new JSPresenter(this);
        presenter.getTest(new JSContontract.View() {
            @Override
            public void onTest(String result) {
                Document doc = Jsoup.parse(result);
                Elements index_left=doc.select("div[class=index_left]");
                Elements ul = index_left.select("ul[class=ul960c]");
                Elements li = ul.select("li");
                for (Element element : li) {
                    Elements a = element.select("a");
                    if (a!=null&&a.size()>0){
                        String linkHref = a.get(0).attr("href");
                        System.out.println("a标签 -->  " + linkHref);
                    }
                    Elements img = element.select("img");
                    if (img!=null&&img.size()>0){
                        String src = img.get(0).attr("src");
                        System.out.println("src标签 -->  " + src);
                    }
                    Elements span = element.select("span");
                    if (span!=null&&span.size()>0){
                        String spanText = span.get(0).text();
                        System.out.println("span标签 -->  " + spanText);
                    }
                }
            }
        });
    }

    public void onBtn1(View view) {
    }

}
